package cn.weiwh.mailsend.mail.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by cuizhixiang on 2017/5/31.
 * 过去资源文件数据
 **/
@Component
public class ConfigReadInit {
    private static final Logger logger= LoggerFactory.getLogger(ConfigReadInit.class);
    private static final String PROPERTIES_DEFAULT = "ConfigureConfig.properties";
    //email
    public static String protocol;
    public static String host;
    public static String port;
    public static String userName;
    public static String passWord;
    public static String emailForm;
    public static String todo;
    public static String timeout;
    public static String is_auth;
    public static String enabled_debug_mod;
    public static String title;
    public static String content;
    public static Properties properties;


    //file
    public static String fileFrom;
    public static String fileTo;
    static{
        init();
    }

    /**
     * 初始化
     */
    private static void init() {
        properties = new Properties();
        try{
            InputStream inputStream = ConfigReadInit.class.getClassLoader().getResourceAsStream(PROPERTIES_DEFAULT);
            properties.load(inputStream);
            inputStream.close();
            //email
            protocol = properties.getProperty("email.protocol");
            host = properties.getProperty("email.host");
            port = properties.getProperty("email.port");
            userName = properties.getProperty("email.user");
            passWord = properties.getProperty("email.pwd");
            emailForm = properties.getProperty("email.from");
            todo = properties.getProperty("email.todo");
            timeout = properties.getProperty("email.timeout");
            is_auth = properties.getProperty("email.is_auth");
            enabled_debug_mod = properties.getProperty("email.enabled_debug_mod");
            title = properties.getProperty("email.title");
            content = properties.getProperty("email.content");
            //file
            fileFrom = properties.getProperty("file.from");
            fileTo = properties.getProperty("file.to");

        } catch(IOException e){
            logger.info("wwh---加载ConfigureConfig.properties时出错！");
            e.printStackTrace();
        }
    }


}
